package com.atgugu.realtime.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/12/29 10:03
 */
public class RedisUtil {
    private static JedisPool pool;
    
    static {
        JedisPoolConfig conf = new JedisPoolConfig();
        conf.setMaxTotal(300); // 提供的最大redis连接数
        conf.setMaxIdle(10); // 允许的最大空闲连接数
        conf.setMaxWaitMillis(10000); // 获取连接的最大等待时间
        conf.setTestOnCreate(true);
        conf.setTestOnBorrow(true);
        conf.setTestOnReturn(true);
        pool = new JedisPool(conf, "hadoop162", 6379);
    }
    
    public static Jedis getRedisClient() {
        Jedis jedis = pool.getResource();
        jedis.select(1);
        return jedis;
    }
}
